<?php
require_once('Zend/Db/Table/Abstract.php');

/**
 * Add your description here
 * 
 * @author 
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

class Default_Model_DbTable_Images extends Zend_Db_Table_Abstract
{
        /**
         * $_name - name of database table
         *
         * @var string
         */
	protected $_name='images';

        /**
         * $_id - this is the primary key of images table
         *        int(10) unsigned         
         *
         * @var int         
         */
	protected $_id='id';

        public function countAllRows() {
            $query = $this->select()->from($this->_name, 'count(*) as all_count');
            $numRows = $this->fetchRow($query);
            return $numRows['all_count'];
        }

        public function getPrimaryKeyName() {
            return $this->_id;
        }

        public function countRowsByGroupId($groupId) {
            $row = $this->select()->from($this->_name, 'count(*) as all_count')->where('group_id = '.$groupId)->query()->fetch();
            return $row['all_count'];
        }

        public function getImagesByGroupId($groupId,$orderBy=null,$limit=null) {
           $select = $this->select()->from($this->_name)->where('group_id = '.$groupId);
           if (!is_null($orderBy))
                 $select=$select->order($orderBy);
           if (!is_null($limit))
                 $select=$select->limit($limit);
           $result=$select->query()->fetchAll();
           return $result;

        }
}


